package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.utils.PageResult;
import com.bawei.es.service.EsDocService;
import com.bawei.mall.product.domain.dto.EsDocFindDTO;
import com.bawei.mall.product.domain.vo.EsDocFindVO;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.domain.vo.EsDocQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "Es文档管理")
@RequestMapping("/esDoc")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;

    @PostMapping("/batchInsertDocs")
    @ApiOperation(value = "批量插入文档")
    public R<Boolean>  batchInsertDocs(@RequestBody List<EsDocInsertVo> esDocInsertVo){
        return esDocService.batchInsertDocs(esDocInsertVo);
    }

    @PostMapping("/queryDocs")
    @ApiOperation(value = "根据传入条件查询Es的文档数据")
    public R  queryDocs(@RequestBody EsDocQueryVo esDocInsertVo){
        return esDocService.queryDocs(esDocInsertVo);
    }

    @PostMapping("/batch")
    @ApiOperation(value ="批添")
    public R batch(@RequestBody List<EsDocInsertVo> esDocInsertVos){
        esDocService.batch(esDocInsertVos);
        return R.ok();
    }

    @PostMapping("/del")
    @ApiOperation(value = "单删")
    public R del(@RequestParam("indexName") String indexName,@RequestParam("id") Long id){
        esDocService.del(indexName,id);
        return R.ok();
    }

    @PostMapping("/querySuggestions")
    @ApiOperation("自动补全")
    public R querySuggestions(@RequestParam("indexName") String indexName,@RequestParam("keyWord") String keyWord,@RequestParam("suggestFiled") String suggestFiled){
        R r = esDocService.querySuggestions(indexName, keyWord, suggestFiled);
        return r;
    }

    /**
     * es列表查询
     * 检索
     */
    @PostMapping("/findEsDocs")
    @ApiOperation(value = "es列表查询")
    public R<PageResult<EsDocFindDTO>> findEsDocs(@RequestBody EsDocFindVO esDocFindVO){
        return esDocService.findEsDocs(esDocFindVO);
    }



}
